package cn.walls1717.ggkt.live.controller;


import cn.walls1717.ggkt.live.service.LiveCourseAccountService;
import cn.walls1717.ggkt.live.service.LiveCourseService;
import cn.walls1717.ggkt.model.live.LiveCourse;
import cn.walls1717.ggkt.model.live.LiveCourseAccount;
import cn.walls1717.ggkt.result.Result;
import cn.walls1717.ggkt.vo.live.LiveCourseConfigVo;
import cn.walls1717.ggkt.vo.live.LiveCourseFormVo;
import cn.walls1717.ggkt.vo.live.LiveCourseVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 直播课程相关接口
 *
 * @author walls1717
 * @since 2022/07/23
 */
@Api(tags = "直播课程相关接口")
@RestController
@RequestMapping("/admin/live/liveCourse")
public class LiveCourseController {

    @Autowired
    private LiveCourseService liveCourseService;

    @Autowired
    private LiveCourseAccountService liveCourseAccountService;

    @ApiOperation("直播课程分页展示")
    @GetMapping("{pageNum}/{pageSize}")
    public Result<Page<LiveCourse>> listPages(@PathVariable Long pageNum, @PathVariable Long pageSize) {
        Page<LiveCourse> pageInfo = liveCourseService.listPages(pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @ApiOperation("直播课程添加")
    @PostMapping("save")
    public Result<?> saveLiveCourse(@RequestBody LiveCourseFormVo liveCourseFormVo) {
        liveCourseService.saveLiveCourse(liveCourseFormVo);
        return Result.success();
    }

    @ApiOperation("删除直播课程")
    @DeleteMapping("remove/{id}")
    public Result<?> deleteLiveCourseById(@PathVariable Long id) {
        liveCourseService.deleteLiveCourseById(id);
        return Result.success();
    }

    @ApiOperation("获取LiveCourse")
    @GetMapping("get/{id}")
    public Result<LiveCourse> getLiveCourseById(@PathVariable Long id) {
        LiveCourse liveCourse = liveCourseService.getById(id);
        return Result.success(liveCourse);
    }

    @ApiOperation("获取LiveCourseFormVo")
    @GetMapping("getInfo/{id}")
    public Result<LiveCourseFormVo> getLiveCourseFormById(@PathVariable Long id) {
        return Result.success(liveCourseService.getLiveCourseFormById(id));
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public Result<?> updateLiveCourse(@RequestBody LiveCourseFormVo liveCourseVo) {
        liveCourseService.updateLiveCourse(liveCourseVo);
        return Result.success();
    }

    @ApiOperation("获取直播账号信息")
    @GetMapping("getLiveCourseAccount/{id}")
    public Result<LiveCourseAccount> getLiveCourseAccountById(@PathVariable Long id) {
        return Result.success(liveCourseAccountService.getLiveCourseAccountById(id));
    }

    @ApiOperation("获取配置信息")
    @GetMapping("getCourseConfig/{id}")
    public Result<LiveCourseConfigVo> getCourseConfigById(@PathVariable Long id) {
        return Result.success(liveCourseService.getCourseConfigById(id));
    }

    @ApiOperation(value = "修改配置")
    @PutMapping("updateConfig")
    public Result<?> updateLiveConfig(@RequestBody LiveCourseConfigVo liveCourseConfigVo) {
        liveCourseService.updateLiveConfig(liveCourseConfigVo);
        return Result.success();
    }

    @ApiOperation("获取最近的直播")
    @GetMapping("findLatelyList")
    public Result<List<LiveCourseVo>> listLatelyLives() {
        return Result.success(liveCourseService.listLatelyLives());
    }
}

